static waypoint *wpt_tmp = NULL;
static int wpt_tmp_valid = 0;
-static route_head *track = NULL;
+static int item_count = -1;
static int waypoints = 0;
+static route_head *route = NULL;
+
FILE *fd;
FILE *ofd;
#define MYNAME "TourExchangeFormat"
-// void DBG(const char *func)
-// {
-// printf("DBG(%s)=in %s\n", MYNAME, func);
-// }
-
-
#if NO_EXPAT
void
tef_xml_rd_init(const char *fname)
#else
-static xg_callback tef_start, tef_item_end, tef_list_start, tef_header, tef_list_end;
-static xg_callback tef_item_start, tef_point;
+static xg_callback tef_start, tef_header, tef_list_start, tef_list_end;
+static xg_callback tef_item_start, tef_point, tef_item_end;
static
xg_tag_mapping tef_xml_map[] = {
{ tef_start, cb_start, "/TEF" },
{ tef_header, cb_start, "/TEF/Header" },
- { tef_list_start, cb_start, "/TEF/WaypointList" },
+ { tef_list_start, cb_start, "/TEF/WaypointList" },
{ tef_item_start, cb_start, "/TEF/WaypointList/Item" },
{ tef_point, cb_start, "/TEF/WaypointList/Item/Point" },
{ tef_item_end, cb_end, "/TEF/WaypointList/Item" },
tef_header(const char *args, const char **attrv)
{
const char **avp = &attrv[0];
- char buff[1024];
-
- track = route_head_alloc();
-
- while (*avp) {
- if (strcmp(avp[0], "Name") == 0)
- {
- track->rte_name = xstrdup(str_utf8_to_cp1252(avp[1]));
- }
- else if (strcmp(avp[0], "Software") == 0)
- {
- track->rte_desc = xstrdup(str_utf8_to_cp1252(avp[1]));
- }
- avp+=2;
- }
-
- if (!track->rte_name) track->rte_name = xstrdup("No name");
- if (!track->rte_desc) track->rte_desc = xstrdup("No description");
- route_add_head(track);
+ route = route_head_alloc();
+ while (*avp)
+ {
+ if (strcmp(avp[0], "Name") == 0)
+ {
+ route->rte_name = str_utf8_to_cp1252(avp[1]);
+ }
+ else if (strcmp(avp[0], "Software") == 0)
+ {
+ route->rte_desc = str_utf8_to_cp1252(avp[1]);
+ }
+ avp+=2;
+ }
+ route_add_head(route);
}
-
/*
- * tef_list_start:
+ *
*/
-
-void
-tef_list_start(const char *args, const char **unused)
+
+void
+tef_list_start(const char *args, const char **attrv)
{
- if (!track)
+ const char **avp = &attrv[0];
+
+ while (*avp)
{
- track = route_head_alloc();
- track->rte_name = xstrdup("Unknown");
- route_add_head(track);
- }
+ if (strcmp(avp[0], "ItemCount") == 0)
+ {
+ sscanf(avp[1], "%d", &item_count);
+ }
+ avp+=2;
+ }
}
/*
if (force || wpt_tmp_valid > 0)
{
waypt_add(wpt_tmp);
- if (track)
+ if (route)
{
waypoint *wpt = waypt_new();
wpt->shortname = xstrdup(wpt_tmp->shortname);
wpt->description = xstrdup(wpt_tmp->description);
- wpt->creation_time = wpt_tmp->creation_time;
wpt->latitude = wpt_tmp->latitude;
wpt->longitude = wpt_tmp->longitude;
- route_add_wpt(track, wpt);
+ route_add_wpt(route, wpt);
wpt_tmp = NULL;
}
}
+ else
+ {
+ waypt_free(wpt_tmp);
+ wpt_tmp = NULL;
+ }
}
-
/*
*
*/
tef_list_end(const char *args, const char **unused)
{
waypoint_final(1);
- waypoints++;
+ if (waypoints != item_count)
+ {
+ fatal(MYNAME ": count waypoints differ to interlal ItemCount!\n");
+ }
}
/*
tef_item_start(const char *args, const char **attrv)
{
const char **avp = &attrv[0];
- const char buf[1024];
wpt_tmp = waypt_new();
wpt_tmp_valid = 0;
- wpt_tmp->creation_time = current_time();
while (*avp)
{
if (0 == strcmp(avp[0], "PointDescription"))
{
-// sprintf(buf, "%04i-%s", waypoints, str_utf8_to_cp1252(avp[1]));
- sprintf(buf, "%s", str_utf8_to_cp1252(avp[1]));
- wpt_tmp->shortname = xstrdup(buf);
+ wpt_tmp->shortname = str_utf8_to_cp1252(avp[1]);
}
if (0 == strcmp(avp[0], "SegDescription"))
{
- wpt_tmp->description = xstrdup(str_utf8_to_cp1252(avp[1]));
+ wpt_tmp->description = str_utf8_to_cp1252(avp[1]);
}
if ((0 == strcmp(avp[0], "ViaStation")) && (0 == strcmp(avp[1], "true")))
{
const char **avp = &attrv[0];
char *comma;
- while (*avp) {
- if (strcmp(avp[0], "y") == 0)
- {
- comma = strstr(avp[1], ",");
- if (comma) *comma='.';
- sscanf(avp[1], "%lf", &wpt_tmp->latitude);
- }
- else if (strcmp(avp[0], "x") == 0)
- {
- comma = strstr(avp[1], ",");
- if (comma) *comma='.';
- sscanf(avp[1], "%lf", &wpt_tmp->longitude);
- }
- avp+=2;
+ while (*avp)
+ {
+ if (strcmp(avp[0], "y") == 0)
+ {
+ comma = strstr(avp[1], ",");
+ if (comma) *comma='.';
+ sscanf(avp[1], "%lf", &wpt_tmp->latitude);
+ }
+ else if (strcmp(avp[0], "x") == 0)
+ {
+ comma = strstr(avp[1], ",");
+ if (comma) *comma='.';
+ sscanf(avp[1], "%lf", &wpt_tmp->longitude);
+ }
+ avp+=2;
}
}
ff_vecs_t tef_xml_vecs = {
ff_type_file,
- { ff_cap_none, ff_cap_none, ff_cap_write },
+ { ff_cap_none, ff_cap_none, ff_cap_read },
tef_xml_rd_init,
NULL,
tef_xml_rd_deinit,